// nvue common mixins
import md5Libs from "uview-ui/libs/function/md5";       //引入md5加密方式
const md5 = md5Libs.md5;
import dayjs from 'dayjs';                            //引入时间格式化插件 dayjs https://dayjs.fenxianglu.cn/
const baseUrl = uni.getStorageSync('baseUrl');          //获取接口根路径
const token = uni.getStorageSync("token");          //获取token
export default {
    data(){
        return{

        }
    },
    methods:{
        http(path = "", params = {}, method = "POST"){
            // 前端åÅ本地存储方法  暂未完成
            // let cacheMap = new Map();
            // let cacheKey = {path,params};
            // console.log(cacheKey)
            // if(cacheMap.has(cacheKey)) return  cacheMap.get(cacheMap);
        return new Promise((resolve, reject) => {
            uni.request({
                url: `${baseUrl}/${path}?t=${new Date().getTime()}`,
                method: method,
                data: {
                    api_token: md5(
                        `${path}${dayjs().format('YYYY-MM-DD')}yiling6670238160ravntyoneapp7926`
                    ),
                    client_id: 1,
                    token,
                    ...params,
                },
                success: (res) => {
                    resolve(res);

                },
                fail: (err) => {
                    reject(err);
                },
            });
        });
    },
        linkTo(url,type='default'){
            console.log(type)
                if(type==='switchTab'){
                   return  uni.switchTab({
                        url:url
                    });
                }
                if(type==='back'){
                 return    uni.navigateTo({
                    });
                }
                if(type==='redict'){
                  return   uni.redirectTo({
                        url: url
                    });
                }
            uni.navigateTo({
                url: url
            })
        }
    }
}

